<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Exercise 4.31: Design of a cantilever beam (GP)</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/cvxbook/Ch04_cvx_opt_probs/html/cantilever_beam.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Exercise 4.31: Design of a cantilever beam (GP)</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Almir Mutapcic - 01/30/06</span>
<span class="comment">% Updated to use GP mode 02/08/06</span>
<span class="comment">% (a figure is generated)</span>
<span class="comment">%</span>
<span class="comment">% We have a segmented cantilever beam with N segments. Each segment</span>
<span class="comment">% has a unit length and variable width and height (rectangular profile).</span>
<span class="comment">% The goal is minimize the total volume of the beam, over all segment</span>
<span class="comment">% widths w_i and heights h_i, subject to constraints on aspect ratios,</span>
<span class="comment">% maximum allowable stress in the material, vertical deflection y, etc.</span>
<span class="comment">%</span>
<span class="comment">% The problem can be posed as a geometric program (posynomial form)</span>
<span class="comment">%     minimize    sum( w_i* h_i)</span>
<span class="comment">%         s.t.    w_min &lt;= w_i &lt;= w_max,       for all i = 1,...,N</span>
<span class="comment">%                 h_min &lt;= h_i &lt;= h_max</span>
<span class="comment">%                 S_min &lt;= h_i/w_i &lt;= S_max</span>
<span class="comment">%                 6*i*F/(w_i*h_i^2) &lt;= sigma_max</span>
<span class="comment">%                 6*F/(E*w_i*h_i^3) == d_i</span>
<span class="comment">%                 (2*i - 1)*d_i + v_(i+1) &lt;= v_i</span>
<span class="comment">%                 (i - 1/3)*d_i + v_(i+1) + y_(i+1) &lt;= y_i</span>
<span class="comment">%                 y_1 &lt;= y_max</span>
<span class="comment">%</span>
<span class="comment">% with variables w_i, h_i, d_i, (i = 1,...,N) and v_i, y_i (i = 1,...,N+1).</span>
<span class="comment">% (Consult the book for other definitions and a recursive formulation of</span>
<span class="comment">% this problem.)</span>

<span class="comment">% optimization variables</span>
N = 8;

<span class="comment">% constants</span>
wmin = .1; wmax = 100;
hmin = .1; hmax = 6;
Smin = 1/5; Smax = 5;
sigma_max = 1;
ymax = 10;
E = 1; F = 1;

cvx_begin <span class="string">gp</span>
  <span class="comment">% optimization variables</span>
  variables <span class="string">w(N)</span> <span class="string">h(N)</span> <span class="string">v(N+1)</span> <span class="string">y(N+1)</span>;

  <span class="comment">% objective is the total volume of the beam</span>
  <span class="comment">% obj = sum of (widths*heights*lengths) over each section</span>
  <span class="comment">% (recall that the length of each segment is set to be 1)</span>
  minimize( w'*h )
  subject <span class="string">to</span>
    <span class="comment">% non-recursive formulation</span>
    d = 6*F*ones(N,1)./(E*ones(N,1).*w.*h.^3);
    <span class="keyword">for</span> i = 1:N
      (2*i-1)*d(i) + v(i+1) &lt;= v(i);
      (i-1/3)*d(i) + v(i+1) + y(i+1) &lt;= y(i);
    <span class="keyword">end</span>

    <span class="comment">% constraint set</span>
    wmin &lt;= w    &lt;= wmax;
    hmin &lt;= h    &lt;= hmax;
    Smin &lt;= h./w &lt;= Smax;
    6*F*[1:N]'./(w.*(h.^2)) &lt;= sigma_max;
    y(1) &lt;= ymax;
cvx_end

<span class="comment">% display results</span>
disp(<span class="string">'The optimal widths and heights are: '</span>);
w, h
fprintf(1,<span class="string">'The optimal minimum volume of the beam is %3.4f.\n'</span>, sum(w.*h))

<span class="comment">% plot the 3D model of the optimal cantilever beam</span>
figure, clf
cantilever_beam_plot([h; w])
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Successive approximation method to be employed.
   sedumi will be called several times to refine the solution.
   Original size: 225 variables, 144 equality constraints
   48 exponentials add 384 variables, 240 equality constraints
-----------------------------------------------------------------
 Cones  |             Errors              |
Mov/Act | Centering  Exp cone   Poly cone | Status
--------+---------------------------------+---------
  8/  8 | 2.949e+00  6.560e-01  1.365e-07 | Solved
  8/  8 | 2.417e-01  4.179e-03  1.926e-07 | Solved
  8/  8 | 1.636e-02  1.932e-05  2.106e-07 | Solved
  7/  8 | 1.028e-03  2.853e-07  2.123e-07 | Solved
  0/  8 | 6.427e-05  2.153e-07  2.127e-07 | Solved
-----------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +40.9668
The optimal widths and heights are: 

w =

    0.6214
    0.7830
    0.8963
    0.9865
    1.0627
    1.1292
    1.1888
    1.3333


h =

    3.1072
    3.9149
    4.4814
    4.9324
    5.3133
    5.6462
    5.9439
    6.0000

The optimal minimum volume of the beam is 40.9668.
</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="cantilever_beam__01.png" alt=""> 
</div>
</div>
</body>
</html>